package com.dhcc.bpm.modules.sandbox.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.dhcc.bpm.common.annotation.Log;
import com.dhcc.bpm.common.enums.BusinessType;
import com.dhcc.bpm.modules.sandbox.entity.ParamConfig;
import com.dhcc.bpm.modules.sandbox.service.IParamConfigService;
import com.dhcc.bpm.modules.sandbox.vo.ParamConfigVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.log.annotation.ApiLog;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 动态报文表 控制器
 *
 * @author donghang
 * @since 2020-03-08
 */
@RestController
@AllArgsConstructor
@RequestMapping("bpm-sandbox/paramconfig")
@Api(value = "动态报文表", tags = "动态报文表接口")
public class ParamConfigController extends BladeController {

	private IParamConfigService paramConfigService;

	/**
	 * 详情
	 */
	@GetMapping("/detail")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "详情", notes = "传入paramConfig")
	@ApiLog("查询参数配置详情")
	@Log(title = "查询参数配置详情", businessType = BusinessType.SELECT)
	public R<ParamConfig> detail(ParamConfig paramConfig) {
        Long opcCodeId = paramConfig.getOpcCodeId();
        ParamConfig detail = paramConfigService.getByCodeId(opcCodeId);
		return R.data(detail);
	}

	/**
	 * 分页 动态报文表
	 */
	@GetMapping("/list")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "分页", notes = "传入paramConfig")
	@ApiLog("分页查询动态报文表")
	@Log(title = "分页查询动态报文表", businessType = BusinessType.SELECT)
	public R<IPage<ParamConfig>> list(ParamConfig paramConfig, Query query) {
		IPage<ParamConfig> pages = paramConfigService.page(Condition.getPage(query), Condition.getQueryWrapper(paramConfig));
		return R.data(pages);
	}

	/**
	 * 自定义分页 动态报文表
	 */
	@GetMapping("/page")
	@ApiOperationSupport(order = 3)
	@ApiOperation(value = "分页", notes = "传入paramConfig")
	@ApiLog("分页查询动态报文表")
	@Log(title = "分页查询动态报文表", businessType = BusinessType.SELECT)
	public R<IPage<ParamConfigVO>> page(ParamConfigVO paramConfig, Query query) {
		IPage<ParamConfigVO> pages = paramConfigService.selectParamConfigPage(Condition.getPage(query), paramConfig);
		return R.data(pages);
	}

	/**
	 * 新增 动态报文表
	 */
	@PostMapping("/save")
	@ApiOperationSupport(order = 4)
	@ApiOperation(value = "新增", notes = "传入paramConfig")
	@ApiLog("新增动态报文表")
	@Log(title = "新增动态报文表", businessType = BusinessType.INSERT)
	public R save(@Valid @RequestBody ParamConfig paramConfig) {
		return R.status(paramConfigService.save(paramConfig));
	}

	/**
	 * 修改 动态报文表
	 */
	@PostMapping("/update")
	@ApiOperationSupport(order = 5)
	@ApiOperation(value = "修改", notes = "传入paramConfig")
	@ApiLog("修改动态报文表")
	@Log(title = "修改动态报文表", businessType = BusinessType.UPDATE)
	public R update(@Valid @RequestBody ParamConfig paramConfig) {
		return R.status(paramConfigService.updateById(paramConfig));
	}

	/**
	 * 新增或修改 动态报文表
	 */
	@PostMapping("/submit")
	@ApiOperationSupport(order = 6)
	@ApiOperation(value = "新增或修改", notes = "传入paramConfig")
	@ApiLog("新增或修改动态报文表")
	@Log(title = "新增或修改动态报文表", businessType = BusinessType.UPDATE)
	public R submit(@Valid @RequestBody ParamConfig paramConfig) {
		if(paramConfig.getOpcCodeId() != null){
			ParamConfig param = paramConfigService.getByCodeId(paramConfig.getOpcCodeId());
			if(param !=null){
				//修改
				paramConfig.setId(param.getId());
			}
		}
		return R.status(paramConfigService.saveOrUpdate(paramConfig));
	}

	
	/**
	 * 删除 动态报文表
	 */
	@PostMapping("/remove")
	@ApiOperationSupport(order = 7)
	@ApiOperation(value = "逻辑删除", notes = "传入ids")
	@ApiLog("删除动态报文表")
	@Log(title = "删除动态报文表", businessType = BusinessType.DELETE)
	public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
		return R.status(paramConfigService.deleteLogic(Func.toLongList(ids)));
	}

	
}
